package com.example.springbootdemo.aop;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;
@Slf4j
public class CglibProxyDemo {
  public static void main(String[] args) {
    Target target = new Target();
    Target foo = (Target) Enhancer.create(Target.class, (MethodInterceptor) (obj, method, args1, proxy) -> {
      log.info("before ......");
//      Object invoke = method.invoke(target, args);
//      Object invoke = proxy.invoke(target, args);
      Object invoke = proxy.invokeSuper(obj, args);
      log.info("after ......");
      return invoke;
    });
    foo.foo();
  }
}
